﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

using Aliphant.Interfaces;
using Aliphant.IoC;
using Aliphant.Mvvm.XEvent.Events;
using Aliphant.Mvvm.XEvent.Ioc;
using Aliphant.Mvvm.XEvent.UI;
using Aliphant.UI.Helper;


namespace ScriptDemo.ViewModels
{
    public class WidgetScriptViewModel : BindableBase
    {
        public WidgetScriptViewModel()
        {

        }

        private string _scriptPath = string.Empty;
        public string ScriptPath { get => _scriptPath; set => SetProperty(ref _scriptPath, value); }

        private string _output = string.Empty;
        public string Output { get => _output; set => SetProperty(ref _output, value); }

        private string _input = string.Empty;
        public string Input { get => _input; set => SetProperty(ref _input, value); }

        private string _output2;
        public string Output2 { get => _output2; set => SetProperty(ref _output2, value); }

        public ICommand SelectFilePathCommand
        {
            get => new UICommand<object>(obj =>
            {
                Action<string> callback = (r) =>
                {
                    ScriptPath = r;
                };

                DialogHelper.SelectFileWindow(new WindowEvent()
                {
                    Data = "所有文件(*.*)|*.*",
                    CallBack = callback
                });
            });
        }

        public ICommand ExecuteCommand
        {
            get => new UICommand<object>(async obj =>
            {
                if (string.IsNullOrEmpty(ScriptPath))
                {
                    return;
                }

                Input =  Clipboard.GetText();

                var manager = IoCServer.Container.Resolve<IScriptManager>();
                await manager.ExecuteAsync(ScriptPath, this);
            });
        }

        public void CopyText(string text)
        {
            Clipboard.SetText(text);
        }
    }
}
